﻿Imports System.Data.OleDb
Public Class ThucDonDAO
    Public Function GetThucDon() As DataTable
        Dim sql As String = "select * from ThucDon"
        Dim dt As New DataTable
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub AddThucDon(ByVal newTD As ThucDonDTO)
        Dim sql As String = String.Format("insert into ThucDon(MaMonAn,TenMonAN,DonVi,Gia,TinhTrang,XuatXu) values('{0}','{1}','{2}','{3}','{4}','{5}')", _
                                           newTD.MaMonAn, newTD.TenMonAn, newTD.DonVi, newTD.Gia, newTD.TinhTrang, newTD.XuatSu, newTD.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(Sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Dữ liêu bị sai vui lòng kiểm tra lại !")
        End Try
        cn.Close()
    End Sub

    Public Sub DelThucDon(ByVal delTD As ThucDonDTO)
        Dim sql As String = String.Format("delete from ThucDon where STT={0}", delTD.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub UpdateThucDon(ByVal newTD As ThucDonDTO)
        Dim sql As String = String.Format("update ThucDon set MaMonAn='{0}',TenMonAn='{1}',DonVi='{2}',Gia='{3}',TinhTrang='{4}',XuatXu='{5}' where STT={6}", _
                                          newTD.MaMonAn, newTD.TenMonAn, newTD.DonVi, newTD.Gia, newTD.TinhTrang, newTD.XuatSu, newTD.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Vui lòng kiểu tra lại dữ liệu !")
        End Try
        cn.Close()
    End Sub
End Class
